import BaseJoint
import Joints.HipFSM.StateMachineHJ
from visual import *

# **
# *  'HipJoint', child of 'BaseJoint', contains a Finite State Machine (FSM) and also responsibilities 
# *  for updating and drawing itself. It also Handles Messages and directs Telegrams and corresponding 
# *  MessageDispatcher Instances to the FSM. 'HipJoint' is an active agent whose States are encapsulated 
# *  and interchanged within its FSM, through communications with the MessageDispatcher.
# *
# * PUBLIC FEATURES:
# *    // Constructors
# *    def __init__(self, ID, name, height, velocity, mass, speedMAX, forceMAX, turnRateMAX)
# *
# *    // Methods
# *    def getFSM(self)
# *    def handleMessage(self, msg, telegram)
# *    def render(self)
# *    def update(self, msg, time)
# *
# *    COLLABORATORS:
# *    BaseJoint
# *    Joints.HipFSM.StateMachineHJ
# *    visual
# *
# * MODIFIED:
# * @version 1.0, 2007-04-23 
# * @author Julian Andreou 5422329
# */



class HipJoint(BaseJoint.BaseJoint):
    def __init__(self, ID, name, height, velocity, mass, speedMAX, forceMAX, turnRateMAX):
        BaseJoint.BaseJoint.__init__(self, ID, name, velocity, mass, speedMAX, forceMAX, turnRateMAX, vector(0,height,0), vector(5,5,5), 2)
        self.FSM = Joints.HipFSM.StateMachineHJ.StateMachineHJ(self)
        self.objVIS = sphere(pos=(0,height,0),radius=5,color=color.green)
    
    def getFSM(self):
        return self.FSM
    
    def handleMessage(self, msg, telegram):
        self.FSM.handleMessage(msg, telegram)
        
    def render(self):
        self.objVIS.pos = self.position
            
    def update(self, msg, time):
        self.FSM.update(msg, time)
        self.render()
        

class Pirate(pygame.sprite.Sprite):

   # We'll just accept the x-position here
   def __init__(self, xPosition, yPosition):

      pygame.sprite.Sprite.__init__(self)
      self.image, self.rect = load_image('Pirate.gif', -1)
      screen = pygame.display.get_surface()
      self.area = screen.get_rect()
      self.rect.topleft = xPosition, yPosition


   # The x-position remains the same
   def update(self, xPosition, yPosition):

      self.old = self.rect
      self.rect = self.rect.move(0, yPosition - self.rect.y)
      self.rect = self.rect.move(xPosition - self.rect.x, 0)

